home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / man.c < prev    next >
C/C++ Source or Header  |  2000-09-29  |  10KB  |  404 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                   ATUtilities Utility Manager                 ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include "ATUtilities.h"
  10.  
  11. UBYTE *PrefsName="AT:Prefs/UtilityManager.prefs";
  12. UBYTE *ManagerPort="--* The ATUtilities Utility Manager *--";
  13. UBYTE *HelpName="AT:Help/UtilityManager.help";
  14.  
  15. struct Library *ATUtilitiesBase;
  16. struct Library *GfxBase;
  17. struct Library *IntuitionBase;
  18.  
  19. struct MsgPort   *Port;
  20. struct TextFont  *opal;
  21. struct ATUtility  ATUtility[13];
  22. APTR              MenuStrip;
  23. UWORD             Count;
  24.  
  25. VOID OpenAll();
  26. VOID CloseAll();
  27. VOID Editieren();
  28. VOID ShowInfo();
  29. BYTE Zeigen();
  30.  
  31. VOID main()
  32. {
  33.  REGISTER BYTE ende;
  34.  
  35.  OpenAll();
  36.  
  37.  ende=0;
  38.  do
  39.   {
  40.    ende=Zeigen();
  41.    if(ende>0) Editieren(ende-1);
  42.   } while(ende!=0);
  43.  CloseAll();
  44. }
  45.  
  46.  
  47. VOID OpenAll()
  48. {
  49.  REGISTER UWORD              i;
  50.  register struct FileHandle *fh;
  51.  register struct MsgPort    *p;
  52.  
  53.  IntuitionBase=OpenLibrary("intuition.library",0L);
  54.  GfxBase=OpenLibrary("graphics.library",0L);
  55.  if((IntuitionBase==NULL)||(GfxBase==NULL)) CloseAll();
  56.  
  57.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  58.  if(ATUtilitiesBase==NULL)
  59.   {
  60.    printf("Kann ATUtilities-Library nicht öffnen.\n");
  61.    CloseAll();
  62.   }
  63.  
  64.  p=FindPort(ManagerPort);
  65.  if(p!=NULL)
  66.   {
  67.    InfoRequest("Der Utility-Manager ist bereits aktiv!");
  68.    CloseAll();
  69.   }
  70.  
  71.  Port=CreatePort(ManagerPort,0L);
  72.  if(Port==NULL)
  73.   {
  74.    ErrorRequest(ERROR_PORT);
  75.    CloseAll();
  76.   }
  77.  
  78.  opal=GetOpalFont();
  79.  
  80.  for(i=0;i<=12;i++)
  81.   {
  82.    strcpy(&ATUtility[i].PortName,"");
  83.    strcpy(&ATUtility[i].Name,"");
  84.   }
  85.  Count=0;
  86.  
  87.  fh=Open(PrefsName,MODE_OLDFILE);
  88.  if(fh!=NULL)
  89.   {
  90.    Read(fh,&Count,2L);
  91.    if(Count<=12)
  92.     {
  93.      for(i=0;i<=Count;i++)
  94.       {
  95.        Read(fh,&ATUtility[i],sizeof(struct ATUtility));
  96.       }
  97.     }
  98.    else
  99.     {
  100.      Count=0;
  101.     }
  102.    Close(fh);
  103.   }
  104.  if(Count==0)
  105.   {
  106.    strcpy(&ATUtility[0].Name,"ATUtilities Library");
  107.    strcpy(&ATUtility[0].PortName,"");
  108.   }
  109. }
  110.  
  111.  
  112. VOID CloseAll()
  113. {
  114.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  115.  if(GfxBase) CloseLibrary(GfxBase);
  116.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  117.  if(Port) DeletePort(Port);
  118.  exit(0);
  119. }
  120.  
  121.  
  122. BYTE Zeigen()
  123. {
  124.  BYTE                 b;
  125.  UWORD                i,j,Code;
  126.  BOOL                 ende;
  127.  ULONG                Class;
  128.  struct Window       *win;
  129.  struct RastPort     *rp;
  130.  struct Gadget       *gad;
  131.  struct IntuiMessage *msg;
  132.  struct FileHandle   *fh;
  133.  
  134.  i=(Count+1)*14+29+BorderHeight(); b=0;
  135.  win=CreateStdWindow("ATUtility Manager - Übersicht",
  136.                      25,25,590,i,
  137.                      CLOSEWINDOW|GADGETUP|MENUPICK,
  138.                      WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|ACTIVATE|GIMMEZEROZERO);
  139.  if(win!=NULL)
  140.   {
  141.    rp=win->RPort;
  142.    SetFont(rp,opal);
  143.    MenuStrip=BuildMenuStrip(win,AUTOFRONTPEN,AUTOBACKPEN);
  144.    if(MenuStrip!=NULL)
  145.     {
  146.      AddMenu(MenuStrip,"Datei",5,120);
  147.      AddItem(MenuStrip,"Informationen zum Programm",300,'I',TRUE,TRUE);
  148.      AddItem(MenuStrip,"Hilfe zum Programm",300,'H',TRUE,TRUE);
  149.      AddItem(MenuStrip,GetOpalLine(),300,0,FALSE,FALSE);
  150.      AddItem(MenuStrip,"Programm beenden",300,'Q',TRUE,TRUE);
  151.      UseMenuStrip(MenuStrip);
  152.     }
  153.  
  154.    CreateBoolGadget(win,10,5,210,12,"Einstellungen Okay",1000);
  155.    CreateBoolGadget(win,225,5,50,12,"Neu",3000);
  156.    CreateBoolGadget(win,280,5,50,12,"Hilfe",4000);
  157.    CreateBoolGadget(win,340,5,240,12,"Information",2000);
  158.    for(i=0;i<=Count;i++)
  159.     {
  160.      j=25+(i*14);
  161.      if(i!=Count)
  162.       {
  163.        CreateBoolGadget(win,10,j,20,12,"!",i+1);
  164.        CreateBoolGadget(win,35,j,90,12,"Aufrufen",100+i);
  165.        CreateBoolGadget(win,130,j,90,12,"Entfernen",200+i);
  166.       }
  167.      CreateBoolGadget(win,225,j,50,12,"Info",300+i);
  168.      CreateBoolGadget(win,280,j,50,12,"Hilfe",400+i);
  169.      DrawNTextBorder(win,340,j,240,12,&ATUtility[i].Name);
  170.     }
  171.    ende=FALSE;
  172.    while(ende==FALSE)
  173.     {
  174.      WaitPort(win->UserPort);
  175.      msg=GetMsg(win->UserPort);
  176.      Class=msg->Class;
  177.      Code=msg->Code;
  178.      gad=msg->IAddress;
  179.      ReplyMsg(msg);
  180.      switch(Class)
  181.       {
  182.        case CLOSEWINDOW:
  183.          ende=TRUE; b=0;
  184.         break;
  185.        case MENUPICK:
  186.          i=MENUNUM(Code);
  187.          j=ITEMNUM(Code);
  188.          if(i==0)
  189.           {
  190.            switch(j)
  191.             {
  192.              case 0:
  193.                ende=TRUE; b=0;
  194.               break;
  195.              case 2:
  196.                Help(HelpName,0);
  197.               break;
  198.              case 3:
  199.                ShowInfo();
  200.               break;
  201.             }
  202.           }
  203.         break;
  204.        case GADGETUP:
  205.          i=gad->GadgetID;
  206.          if(i<100)
  207.           {
  208.            ende=TRUE;
  209.            b=(BYTE)i;
  210.           }
  211.          else if(i<200) Utility(&ATUtility[i-100].PortName,UTILITY_CALL);
  212.          else if(i<300) Utility(&ATUtility[i-200].PortName,UTILITY_QUIT);
  213.          else if(i<400)
  214.           {
  215.            if(i!=300+Count)
  216.             {
  217.              Utility(&ATUtility[i-300].PortName,UTILITY_INFO);
  218.             }
  219.            else
  220.             {
  221.              LibraryInfo();
  222.             }
  223.           }
  224.          else if(i<500)
  225.           {
  226.            if(i!=400+Count)
  227.             {
  228.              Utility(&ATUtility[i-400].PortName,UTILITY_HELP);
  229.             }
  230.            else
  231.             {
  232.              Help(HelpName,0);
  233.             }
  234.           }
  235.          else if(i==1000)
  236.           {
  237.            fh=Open(PrefsName,MODE_NEWFILE);
  238.            if(fh!=NULL)
  239.             {
  240.              Write(fh,&Count,2L);
  241.              for(i=0;i<=Count;i++)
  242.               {
  243.                Write(fh,&ATUtility[i],sizeof(struct ATUtility));
  244.               }
  245.              Close(fh);
  246.             }
  247.            ende=TRUE;
  248.           }
  249.          else if(i==3000)
  250.           {
  251.            if(Count==12)
  252.             {
  253.              MultiRequest("Es können nur maximal 12 Utilities",
  254.                           "Verwaltet werden!","Okay",NULL);
  255.             }
  256.            else
  257.             {
  258.              b=120;
  259.              ende=TRUE;
  260.             }
  261.           }
  262.          else if(i==4000)
  263.           {
  264.            Help(HelpName,0);
  265.           }
  266.          else
  267.           {
  268.            ShowInfo();
  269.           }
  270.         break;
  271.       }
  272.     }
  273.    ClearMenuStrip(win);
  274.    DeleteStdWindow(win);
  275.    RemoveMenuStrip(MenuStrip);
  276.   }
  277.  return(b);
  278. }
  279.  
  280.  
  281. VOID Editieren(num)
  282.  UBYTE num;
  283. {
  284.  REGISTER UWORD                i;
  285.  REGISTER BOOL                 ende;
  286.  REGISTER ULONG                Class;
  287.  REGISTER UBYTE               *name,*port;
  288.  register struct Window       *win;
  289.  register struct RastPort     *rp;
  290.  register struct Gadget       *gad;
  291.  register struct IntuiMessage *msg;
  292.  
  293.  win=CreateStdWindow("ATUtility Manager - Utility ändern/hinzufügen",
  294.                      75,75,450,62+BorderHeight(),
  295.                      CLOSEWINDOW|GADGETUP,
  296.                      WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|ACTIVATE|GIMMEZEROZERO);
  297.  if(win!=NULL)
  298.   {
  299.    rp=win->RPort;
  300.    SetFont(rp,opal);
  301.    CreateBoolGadget(win,10,5,100,12,"Okay",1);
  302.    CreateBoolGadget(win,115,5,100,12,"Abbruch",2);
  303.    if(num!=119)
  304.     {
  305.      CreateBoolGadget(win,305,5,120,12,"Entfernen",3);
  306.      name=&ATUtility[num].Name;
  307.      port=&ATUtility[num].PortName;
  308.     }
  309.    else
  310.     {
  311.      name="";
  312.      port="";
  313.     }
  314.    SelectStdFPen(rp);
  315.    WriteText(rp,20,33,"Name:");
  316.    WriteText(rp,20,52,"Port-Name:");
  317.    name=CreateStringGadget(win,115,24,310,12,name,42,10);
  318.    port=CreateStringGadget(win,115,43,310,12,port,42,20);
  319.    ende=FALSE;
  320.    while(ende==FALSE)
  321.     {
  322.      WaitPort(win->UserPort);
  323.      msg=GetMsg(win->UserPort);
  324.      Class=msg->Class;
  325.      gad=msg->IAddress;
  326.      ReplyMsg(msg);
  327.      switch(Class)
  328.       {
  329.        case CLOSEWINDOW:
  330.          ende=TRUE;
  331.         break;
  332.        case GADGETUP:
  333.          i=gad->GadgetID;
  334.          switch(i)
  335.           {
  336.            case 1:
  337.              if(num==119)
  338.               {
  339.                strcpy(&ATUtility[Count+1].Name,&ATUtility[Count].Name);
  340.                strcpy(&ATUtility[Count+1].PortName,&ATUtility[Count].PortName);
  341.                num=Count;
  342.                Count++;
  343.               }
  344.              strcpy(&ATUtility[num].Name,name);
  345.              strcpy(&ATUtility[num].PortName,port);
  346.              ende=TRUE;
  347.             break;
  348.            case 2:
  349.              ende=TRUE;
  350.             break;
  351.            case 3:
  352.              for(i=num;i<Count;i++)
  353.               {
  354.                strcpy(&ATUtility[i].Name,&ATUtility[i+1].Name);
  355.                strcpy(&ATUtility[i].PortName,&ATUtility[i+1].PortName);
  356.               }
  357.              Count--;
  358.              ende=TRUE;
  359.             break;
  360.           }
  361.         break;
  362.       }
  363.     }
  364.    DeleteStdWindow(win);
  365.   }
  366. }
  367.  
  368. struct InfoItem ii5=
  369. {
  370.  1,1,
  371.  "Service",
  372.  "",
  373.  "Haben Sie Anregungen oder",
  374.  "Verbesserungswünsche?",
  375.  "",
  376.  "",
  377.  "Schreiben Sie an:",
  378.  "",
  379.  "Thomas Dreibholz",
  380.  "Molbachweg 7",
  381.  "D-51674 Wiehl",
  382.  "West Germany"
  383. };
  384.  
  385. struct Info idata=
  386. {
  387.  1,
  388.  &ii5,
  389. };
  390.  
  391. /* Informationen anzeigen */
  392. VOID ShowInfo()
  393. {
  394.  ExtInformationBox(NULL,
  395.                   "ATUtilities Utility-Manager - Information",
  396.                   "$VER: Utility-Manager - Version 4.0",
  397.                   "Copyright (C) 1992-1994 by",
  398.                   "Thomas Dreibholz",
  399.                   "All rights reserved.",
  400.                   "AT:Icons/Manager",
  401.                   &idata);
  402. }
  403.  
  404.